<template>

<div class="headview">
    <p>MBTI职业测试(16型人格)</p>
</div>
<div class="percentline">
    <el-progress :percentage="haha" :color="customColor"  :stroke-width="10" />
</div>
<div class="problempos">
    <p>{{name}}</p>
</div>
<div class="buttonset">
      <button @click="increase" style="height:60px;width:500px;background:transparent;">{{optionA}} </button>
</div>
<div class="okbutton">
    <button @click="increase2" style="height:60px;width:500px;background:transparent;">{{optionB}} </button>
</div>

</template>


<script>
import { ref } from 'vue'
import { getCurrentInstance} from "vue";
import { useRouter } from 'vue-router'
export default{
    setup(){
    const router = useRouter()
    const haha = ref(0)
    const customColor = ref('#409eff')
    const {proxy} = getCurrentInstance()
    const name = ref('')
    const optionA = ref('点击任意按钮开始答题')
    const optionB = ref('点击任意按钮开始答题')
    const JP1 = ref(0)
    const JP2 = ref(0)
    const TF1 = ref(0)
    const TF2 = ref(0)
    const SN1 = ref(0)
    const SN2 = ref(0)
    const EI1 = ref(0)
    const EI2 = ref(0)
    var naid = localStorage.getItem("key");
    console.log(naid)
    var index = ref(0)
    var arr = ref([
        '1','2','3','4','5','6','7','8','9','10','11','12','13','14','15','16','17','18','19','20','21','22','23','24','25','26','27','28','29','30','31','32','33','34','35','36','37','38','39','40',
        '41','42','43','44','45','46','47','48','49','50','51','52','53','54','55','56','57','58','59','60','61','62','63','64','65','66','67','68','69','70','71','72','73','74','75','76','77','78','79',
        '80','81','82','83','84','85','86','87','88','89','90','91','92','93'
            ])
    const obj = {
        numquestion:arr.value[index.value]
    }
        const increase = async () => {
            var account = localStorage.getItem("account")
            var cname = localStorage.getItem("cname")
            var sname = localStorage.getItem("sname")
            obj.numquestion = arr.value[index.value]
            if (index.value < 93) {
                haha.value += 1
                index.value = index.value + 1
                const res = await new proxy.$request(proxy.$urls.m().problem, obj).modepost()
                name.value = res.data.question
                optionA.value = res.data.selequestionA
                optionB.value = res.data.selequestionB
                console.log(res)
            }
            if (index.value <= 21) {
                JP1.value = JP1.value + 1
            }
            else if (index.value > 21 && index.value <= 45) {
                TF1.value = TF1.value + 1
            }
            else if (index.value > 45 && index.value <= 72) {
                SN1.value = SN1.value + 1
            }
            else if (index.value > 72 && index.value <= 92) {
                EI1.value = EI1.value + 1
            }
            if (haha.value >= 93) {
                haha.value = 100
            }
            if (haha.value >92) {
                if (JP1.value > JP2.value) {
                    if (TF1.value > TF2.value) {
                        if (SN1.value > SN2.value) {
                            if (EI1.value > EI2.value) {
                                console.log(account)
                                console.log(cname)
                                console.log(sname)
                                const cs = Date()
                                const obj = {
                                    date1: cs,
                                    sno: account,
                                    resqu: "ESTJ" 
                                }
                                const res = new proxy.$request(proxy.$urls.m().result,obj).modepost()
                                console.log(res)
                               router.push({                                                                   //绑定路由
                                 path: '/estj'
                                })
                                }
                            if (EI1.value < EI2.value){
                                console.log(account)
                                console.log(cname)
                                console.log(sname)
                                const cs1 = Date()
                                const obj1 = {
                                    date1: cs1,
                                    sno: account,
                                    resqu: "ISTJ"
                                }
                                const res = new proxy.$request(proxy.$urls.m().result, obj1).modepost()
                                console.log(res)
                                router.push({                                                                   //绑定路由
                                    path: '/istj'
                                })
                                }
                            }
                        if (SN1.value < SN2.value){
                            if (EI1.value > EI2.value){
                                console.log(account)
                                console.log(cname)
                                console.log(sname)
                                const cs2 = Date()
                                const obj2 = {
                                    date1: cs2,
                                    sno: account,
                                    resqu: "ENTJ"
                                }
                                const res = new proxy.$request(proxy.$urls.m().result, obj2).modepost()
                                console.log(res)
                                   router.push({                                                                   //绑定路由
                                 path: '/entj'
                                })
                                }
                            if (EI1.value < EI2.value){
                                console.log(account)
                                console.log(cname)
                                console.log(sname)
                                const cs3 = Date()
                                const obj3 = {
                                    date1: cs3,
                                    sno: account,
                                    resqu: "INTJ"
                                }
                                const res = new proxy.$request(proxy.$urls.m().result, obj3).modepost()
                                console.log(res)
                                router.push({                                                                   //绑定路由
                                 path: '/intj'
                                })
                                }
                            }
                    }
                    if (TF1.value < TF2.value){
                        if (SN1.value > SN2.value) {
                            if (EI1.value > EI2.value) {
                                console.log(account)
                                console.log(cname)
                                console.log(sname)
                                const cs4 = Date()
                                const obj4 = {
                                    date1: cs4,
                                    sno: account,
                                    resqu: "ESFJ"
                                }
                                const res = new proxy.$request(proxy.$urls.m().result, obj4).modepost()
                                console.log(res)
                                router.push({                                                                   //绑定路由
                                 path: '/esfj'
                                })
                                }
                            if (EI1.value < EI2.value){
                                console.log(account)
                                console.log(cname)
                                console.log(sname)
                                const cs5 = Date()
                                const obj5 = {
                                    date1: cs5,
                                    sno: account,
                                    resqu: "ISTJ"
                                }
                                const res = new proxy.$request(proxy.$urls.m().result, obj5).modepost()
                                console.log(res)
                                router.push({                                                                   //绑定路由
                                 path: '/istj'
                                })
                                }
                            }
                        if (SN1.value < SN2.value){
                            if (EI1.value > EI2.value){
                                console.log(account)
                                console.log(cname)
                                console.log(sname)
                                const cs6 = Date()
                                const obj6 = {
                                    date1: cs6,
                                    sno: account,
                                    resqu: "ENFJ"
                                }
                                const res = new proxy.$request(proxy.$urls.m().result, obj6).modepost()
                                console.log(res)
                                router.push({                                                                   //绑定路由
                                 path: '/enfj'
                                })
                                }
                            if (EI1.value < EI2.value){
                                console.log(account)
                                console.log(cname)
                                console.log(sname)
                                const cs7 = Date()
                                const obj7 = {
                                    date1: cs7,
                                    sno: account,
                                    resqu: "INFJ"
                                }
                                const res = new proxy.$request(proxy.$urls.m().result, obj7).modepost()
                                console.log(res)
                                router.push({                                                                   //绑定路由
                                 path: '/infj'
                                })
                                }
                            }
                    }
                } 
                if (JP1.value < JP2.value){
                    if (TF1.value > TF2.value) {
                        if (SN1.value > SN2.value) {
                            if (EI1.value > EI2.value) {
                                console.log(account)
                                console.log(cname)
                                console.log(sname)
                                const cs8 = Date()
                                const obj8 = {
                                    date1: cs8,
                                    sno: account,
                                    resqu: "ESTP"
                                }
                                const res = new proxy.$request(proxy.$urls.m().result, obj8).modepost()
                                console.log(res)
                                router.push({                                                                   //绑定路由
                                 path: '/estp'
                                })
                                }
                            if (EI1.value < EI2.value){
                                console.log(account)
                                console.log(cname)
                                console.log(sname)
                                const cs9 = Date()
                                const obj9 = {
                                    date1: cs9,
                                    sno: account,
                                    resqu: "ISTP"
                                }
                                const res = new proxy.$request(proxy.$urls.m().result, obj9).modepost()
                                console.log(res)
                                router.push({                                                                   //绑定路由
                                 path: '/istp'
                                })
                                }
                            }
                        if (SN1.value < SN2.value){
                            if (EI1.value > EI2.value){
                                console.log(account)
                                console.log(cname)
                                console.log(sname)
                                const cs10 = Date()
                                const obj10 = {
                                    date1: cs10,
                                    sno: account,
                                    resqu: "ENTP"
                                }
                                const res = new proxy.$request(proxy.$urls.m().result, obj10).modepost()
                                console.log(res)
                                router.push({                                                                   //绑定路由
                                 path: '/entp'
                                })
                                }
                            if (EI1.value < EI2.value){
                                console.log(account)
                                console.log(cname)
                                console.log(sname)
                                const cs11 = Date()
                                const obj11 = {
                                    date1: cs11,
                                    sno: account,
                                    resqu: "INTP"
                                }
                                const res = new proxy.$request(proxy.$urls.m().result, obj11).modepost()
                                console.log(res)
                                router.push({                                                                   //绑定路由
                                 path: '/intp'
                                })
                                }
                            }
                    }
                    if (TF1.value < TF2.value){
                        if (SN1.value > SN2.value) {
                            if (EI1.value > EI2.value) {
                                console.log(account)
                                console.log(cname)
                                console.log(sname)
                                const cs12 = Date()
                                const obj12 = {
                                    date1: cs12,
                                    sno: account,
                                    resqu: "ESFP"
                                }
                                const res = new proxy.$request(proxy.$urls.m().result, obj12).modepost()
                                console.log(res)
                                router.push({                                                                   //绑定路由
                                 path: '/esfp'
                                })
                                }
                            if (EI1.value < EI2.value){
                                console.log(account)
                                console.log(cname)
                                console.log(sname)
                                const cs13 = Date()
                                const obj13 = {
                                    date1: cs13,
                                    sno: account,
                                    resqu: "ISFP"
                                }
                                const res = new proxy.$request(proxy.$urls.m().result, obj13).modepost()
                                console.log(res)
                                router.push({                                                                   //绑定路由
                                 path: '/isfp'
                                })
                                }
                            }
                        if (SN1.value < SN2.value){
                            if (EI1.value > EI2.value){
                                console.log(account)
                                console.log(cname)
                                console.log(sname)
                                const cs14 = Date()
                                const obj14 = {
                                    date1: cs14,
                                    sno: account,
                                    resqu: "ENFP"
                                }
                                const res = new proxy.$request(proxy.$urls.m().result, obj14).modepost()
                                console.log(res)
                                router.push({                                                                   //绑定路由
                                 path: '/enfp'
                                })
                                }
                            if (EI1.value < EI2.value){
                                console.log(account)
                                console.log(cname)
                                console.log(sname)
                                const cs15 = Date()
                                const obj15 = {
                                    date1: cs15,
                                    sno: account,
                                    resqu: "INFP"
                                }
                                const res = new proxy.$request(proxy.$urls.m().result, obj15).modepost()
                                console.log(res)
                                router.push({                                                                   //绑定路由
                                 path: '/infp'
                                })
                                }
                            }
                    }
                }
                    
            }
        }   
     const increase2 = async() => {
        obj.numquestion = arr.value[index.value]
        if (index.value < 93) {
            haha.value += 1
            index.value = index.value + 1
            const res = await new proxy.$request(proxy.$urls.m().problem, obj).modepost()
            name.value = res.data.question
            optionA.value = res.data.selequestionA
            optionB.value = res.data.selequestionB
            console.log(res)
        }

            if (index.value<=21) {
                JP2.value = JP2.value+1
            }
            else if(index.value>21&&index.value<=45){
                TF2.value = TF2.value+1
            }
            else if(index.value>45&&index.value<=72){
                SN2.value = SN2.value+1
            }
            else if(index.value>72&&index.value<=92){
                EI2.value = EI2.value+1
            }

            if (haha.value >= 93) {
            haha.value = 100
    }
               if (haha.value >92) {
                if (JP1.value > JP2.value) {
                    if (TF1.value > TF2.value) {
                        if (SN1.value > SN2.value) {
                            if (EI1.value > EI2.value) {
                               router.push({                                                                   //绑定路由
                                 path: '/estj'
                                })
                                }
                            if (EI1.value < EI2.value){
                                    router.push({                                                                   //绑定路由
                                 path: '/istj'
                                })
                                }
                            }
                        if (SN1.value < SN2.value){
                            if (EI1.value > EI2.value){
                                   router.push({                                                                   //绑定路由
                                 path: '/entj'
                                })
                                }
                            if (EI1.value < EI2.value){
                                    router.push({                                                                   //绑定路由
                                 path: '/intj'
                                })
                                }
                            }
                    }
                    if (TF1.value < TF2.value){
                        if (SN1.value > SN2.value) {
                            if (EI1.value > EI2.value) {
                                router.push({                                                                   //绑定路由
                                 path: '/esfj'
                                })
                                }
                            if (EI1.value < EI2.value){
                                    router.push({                                                                   //绑定路由
                                 path: '/istj'
                                })
                                }
                            }
                        if (SN1.value < SN2.value){
                            if (EI1.value > EI2.value){
                                    router.push({                                                                   //绑定路由
                                 path: '/enfj'
                                })
                                }
                            if (EI1.value < EI2.value){
                                    router.push({                                                                   //绑定路由
                                 path: '/infj'
                                })
                                }
                            }
                    }
                } 
                if (JP1.value < JP2.value){
                    if (TF1.value > TF2.value) {
                        if (SN1.value > SN2.value) {
                            if (EI1.value > EI2.value) {
                                router.push({                                                                   //绑定路由
                                 path: '/estp'
                                })
                                }
                            if (EI1.value < EI2.value){
                                    router.push({                                                                   //绑定路由
                                 path: '/istp'
                                })
                                }
                            }
                        if (SN1.value < SN2.value){
                            if (EI1.value > EI2.value){
                                    router.push({                                                                   //绑定路由
                                 path: '/entp'
                                })
                                }
                            if (EI1.value < EI2.value){
                                    router.push({                                                                   //绑定路由
                                 path: '/intp'
                                })
                                }
                            }
                    }
                    if (TF1.value < TF2.value){
                        if (SN1.value > SN2.value) {
                            if (EI1.value > EI2.value) {
                                router.push({                                                                   //绑定路由
                                 path: '/esfp'
                                })
                                }
                            if (EI1.value < EI2.value){
                                    router.push({                                                                   //绑定路由
                                 path: '/isfp'
                                })
                                }
                            }
                        if (SN1.value < SN2.value){
                            if (EI1.value > EI2.value){
                                    router.push({                                                                   //绑定路由
                                 path: '/enfp'
                                })
                                }
                            if (EI1.value < EI2.value){
                                    router.push({                                                                   //绑定路由
                                 path: '/infp'
                                })
                                }
                            }
                    }
                }
                    
            }
    }

    
    return {
        customColor,
        increase,
        haha,
        arr,
        increase2,
        name,
        optionA,
        optionB,
        JP1,JP2,TF1,TF2,SN1,SN2,EI1,EI2,
        naid
    }
   },
}

</script>
<style>
.headview{
    text-align: center;
    font-weight: bold;
    font-size: 20px;
}
.el-progress{
    width: 50%;
    text-align: center;
    font-weight: bold;
    font-size: 20px;
    transform: translate(-50%, -50%);
    top: 50%;
    left: 50%;
}
.percentline{
    text-align: center;
    font-weight: bold;
    font-size: 20px;
}
.buttonset{
    text-align: center;
    font-weight: bold;
    font-size: 100px;
     border-radius:100%;
}
.okbutton{
    text-align: center;
    font-weight: bold;
    font-size: 60px;
}
.problempos{
    text-align: center;
    font-weight: bold;
    font-size: 20px;
    top: 30%;
}
</style>
